package com.example.shoppingdemo.nslcommodity.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.example.shoppingdemo.R;
import com.example.shoppingdemo.nslcommodity.javabean.AdapterModel;
import com.example.shoppingdemo.nslcommodity.javabean.ShopModel;

import java.util.List;

/**
 * 全部列表的Adapter
 */
public class AllAdapter extends RecyclerView.Adapter<AllAdapter.AllHolder>{
    private onAllParticulars listenter;
    private Context context;
    private List<AdapterModel> adapterModels;

    public void setAdapterModels(List<AdapterModel> adapterModels) {
        this.adapterModels = adapterModels;
    }

    public AllAdapter(Context context) {
        this.context = context;
    }

    public void setListenter(onAllParticulars listenter) {
        this.listenter = listenter;
    }

    @NonNull
    @Override
    public AllHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
      View  baseView = LayoutInflater.from(parent.getContext()).inflate(R.layout.all_item, parent, false);
       AllHolder holder=new AllHolder(baseView);
        return holder;
    }

    @Override
    public void onBindViewHolder(@NonNull AllAdapter.AllHolder holder, int position) {
        holder.smoney.setText("实付款 ￥"+adapterModels.get(position).getSmoney());
        holder.numder.setText("订单编号："+adapterModels.get(position).getNumder());
       switch (adapterModels.get(position).getType()){
           case 0:
               holder.state.setText("待付款");
               break;
           case 1:
               holder.state.setText("待发货");
               break;
           case 2:
               holder.state.setText("待收货");
               break;
           case 3:
               holder.state.setText("待评价");
               break;
           case 4:
               holder.state.setText("无效订单");
               break;
       }
       List<ShopModel> shopModelList=adapterModels.get(position).getShopModelList();
       ShopAdapter shopAdapter=new ShopAdapter(shopModelList);

       holder.recyclerView.setAdapter(shopAdapter);
       holder.recyclerView.setLayoutManager(new LinearLayoutManager(holder.recyclerView.getContext()));
    }

    @Override
    public int getItemCount() {
        return null==adapterModels?0:adapterModels.size();
    }

    class AllHolder extends RecyclerView.ViewHolder{
        RecyclerView recyclerView;
        TextView smoney;
        TextView state;
        LinearLayout layout;
        TextView numder;
        public AllHolder(@NonNull View itemView) {
            super(itemView);
            state=itemView.findViewById(R.id.taxt_all_item_state);
            layout=itemView.findViewById(R.id.layout_all_item);
            smoney=itemView.findViewById(R.id.text_order_all_money);
            recyclerView=itemView.findViewById(R.id.item_all_recycler);
            numder=itemView.findViewById(R.id.text_item_all_numder);
            layout.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    listenter.onAllResult(AllHolder.this.getAdapterPosition());
                }
            });
        }
    }
    public interface onAllParticulars{
        void onAllResult(int position);
    }
}
